package com.minisoft.entity;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.minisoft.utils.CommonUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Date: 2021/07/19/15:42
 */
@Data
public class OpportunityDetailsXcxVo {

    @ApiModelProperty(value = "id")
    private String id;

    @ApiModelProperty(value = "商机Id")
    private String customerOpportunityId;

    @ApiModelProperty(value = "客户id")
    private String customerId;

    @ApiModelProperty(value = "客户主档id")
    private String customerInfoId;

    @ApiModelProperty(value = "案场id")
    private String saleTeamId;

    @ApiModelProperty(value = "姓名")
    @CounterField
    private String customerName;

    @ApiModelProperty(value = "性别（0男1女）")
    @CounterField
    private Integer gender;

    @ApiModelProperty(value = "置业顾问名称")
    private String saleMainName;

    @ApiModelProperty(value = "登录人")
    private String loginUserKey;

    @ApiModelProperty(value = "置业顾问userKey")
    private String saleMainId;

    @ApiModelProperty(value = "经纪人id")
    private String agentId;

    @ApiModelProperty(value = "经纪人姓名")
    private String agentName;

    @ApiModelProperty(value = "经纪人电话")
    private String agentMobile;

    @ApiModelProperty(value = "报备经纪人姓名")
    private String reportAgentName;

    @ApiModelProperty(value = "经纪人类型")
    private String agentStates;

    @ApiModelProperty(value = "联系类型描述（客户来源）id")
    private String contactTypeId;

    @ApiModelProperty(value = "联系类型描述（客户来源）")
    private String contactTypeName;

    @ApiModelProperty(value = "初次来访日期")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date visitFirstDate;

    @ApiModelProperty(value = "最近来访日期")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date visitLastDate;

    @ApiModelProperty(value = "意向单价")
    @CounterField
    private String targetUnitPrice;

    @ApiModelProperty(value = "意向总价描述")
    @TagField
    private String targetTotalPriceName;

    @ApiModelProperty(value = "工作区域ID")
    @CounterField
    private String workArea;

    @ApiModelProperty(value = "工作区域名称")
    private String workAreaName;

    @ApiModelProperty(value = "购房目的描述")
    @TagField
    @CounterField
    private String targetObjectiveName;

    @ApiModelProperty(value = "意向面积描述")
    @TagField
    private String targetAcreageName;

    @ApiModelProperty(value = "意向户型")
    @CounterField
    private String targetHouseType;

    @ApiModelProperty(value = "备注(客户印象)")
    @JSONField(name = "remark")
    private String description;

    @ApiModelProperty(value = "认知途径描述")
    private String channelWayName;

    @ApiModelProperty(value = "来访渠道")
    private String visitChannelId;

    @ApiModelProperty(value = "来访渠道名称")
    private String visitChannelName;

    @ApiModelProperty(value = "项目画像使用")
    private String visitCode;

    @ApiModelProperty(value = "商机状态 2到访，3认筹，4认购，5签约")
    @JSONField(name = "stage")
    private Integer opportunityState;

    @ApiModelProperty(value = "职业")
    @CounterField
    private String professionId;

    @ApiModelProperty(value = "家庭成员构成")
    @CounterField
    private String familyMemberId;

    @ApiModelProperty(value = "已有住房套数")
    @CounterField
    private String livingNum;

    @ApiModelProperty(value = "交通工具")
    @CounterField
    private String vehicle;

    @ApiModelProperty(value = "私车价位段ID")
    @CounterField
    private String carParkId;

    @ApiModelProperty(value = "私车价位段描述")
    private String carParkName;

    @ApiModelProperty(value = "私车品牌")
    @CounterField
    private String carBrandId;

    @ApiModelProperty(value = "业余活动")
    private String activities;

    @ApiModelProperty(value = "证件类型id")
    @CounterField
    private String idCardTypeId;
    @ApiModelProperty(value = "证件类型")
    private String idCardType;
    @CounterField
    @ApiModelProperty(value = "证件号码")
    private String idCardNo;

    @ApiModelProperty(value = "是否限购")
    @CounterField
    private String isLimitedBuy;

    @ApiModelProperty(value = "是否限贷")
    @CounterField
    private String isLimitedLoan;

    @ApiModelProperty(value = "地址")
    @CounterField
    private String address;

    @ApiModelProperty(value = "共享置业顾问的userKey")
    private String shareUserKey;

    @ApiModelProperty(value = "共享置业顾问姓名")
    private String shareSaleMainName;

    @ApiModelProperty(value = "是否为重要客户(1是0否)")
    private Integer isImportance;

    @ApiModelProperty(value = "创建时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty(value = "更新人")
    private String updateId;

    @ApiModelProperty(value = "更新时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @ApiModelProperty(value = "案场名")
    private String saleTeamName;

    @ApiModelProperty(value = "抗销售因素ID")
    @CounterField
    private String salesResistanceId;

    @ApiModelProperty(value = "抗销售因素")
    @TagField
    private String salesResistanceName;

    @ApiModelProperty(value = "客户标签ID")
    @CounterField
    private String customerLabelId;

    @ApiModelProperty(value = "客户标签名称")
    private String customerLabelName;

    @ApiModelProperty(value = " 其他来访渠道")
    private String otherVisitChannelId;

    @ApiModelProperty(value = " 其他来访渠道名称")
    private String otherVisitChannelName;

    @ApiModelProperty(value = " 意向户型描述")
    private String targetHouseTypeName;

    @ApiModelProperty(value = " 意向业态ID")
    @CounterField
    private String targetHouseFormat;

    @ApiModelProperty(value = " 意向业态描述")
    private String targetHouseFormatName;

    @ApiModelProperty(value = " 意向面积段ID")
    @CounterField
    private String targetAcreage;

    @ApiModelProperty(value = " 置业目的")
    @CounterField
    private String targetObjective;

    @ApiModelProperty(value = " 交房标准描述")
    private String targetStandardName;

    @ApiModelProperty(value = " 交房标准")
    private String targetStandard;

    @ApiModelProperty(value = " 意向投资总价")
    @CounterField
    private String targetTotalPrice;

    @ApiModelProperty(value = " 意向单价名称")
    @TagField
    private String targetUnitPriceName;

    @ApiModelProperty(value = " 来访人数名称")
    private String toPersonSumName;

    @ApiModelProperty(value = " 来访人数ID")
    private String toPersonSum;

    @ApiModelProperty(value = " 家庭年收入描述")
    private String familyIncomeName;

    @ApiModelProperty(value = " 家庭年收入")
    @CounterField
    private String familyIncomeId;

    @ApiModelProperty(value = " 家庭成员构成描述")
    @TagField
    private String familyMemberName;

    @ApiModelProperty(value = " 交通工具描述")
    private String vehicleName;

    @ApiModelProperty(value = " 职业/职位描述")
    private String professionName;

    @ApiModelProperty(value = " 私车品牌描述")
    private String carBrandName;

    @ApiModelProperty(value = " 行业描述")
    private String tradeName;

    @ApiModelProperty(value = " 行业")
    @CounterField
    private String tradeId;

    @ApiModelProperty(value = " 已有住房套数描述")
    private String livingNumName;

    @ApiModelProperty(value = " 学历描述")
    private String educationName;

    @ApiModelProperty(value = " 学历")
    @CounterField
    private String educationId;

    @ApiModelProperty(value = " 年龄段描述")
    private String ageStageName;

    @ApiModelProperty(value = " 年龄段")
    @CounterField
    private String ageStage;

    @ApiModelProperty(value = " 客户关注点")
    @CounterField
    private String focusId;

    @ApiModelProperty(value = " 关注点的名称")
    @TagField
    private String focusName;

    @ApiModelProperty(value = " 是否重要客户描述")
    private String isImportantName;

    @ApiModelProperty(value = "认知途径")
    @CounterField
    private String channelWayId;

    @ApiModelProperty(value = "成交几率描述")
    private String chanceName;

    @ApiModelProperty(value = "成交几率")
    private String chanceId;

    @ApiModelProperty(value = "问题客户原因")
    private String problemCustomerReason;

    @ApiModelProperty(value = "来访区域名称")
    private String visitingAreaName;

    @ApiModelProperty(value = "来访区域ID")
    @CounterField
    private String visitingArea;

    @ApiModelProperty(value = "是否潜力客户编码")
    private String isNewPotential;

    @ApiModelProperty(value = "是否潜力客户名称")
    private String isNewPotentialName;

    @ApiModelProperty(value = "国籍ID")
    @CounterField
    private String nationId;

    @ApiModelProperty(value = "国籍描述")
    private String nationName;

    @ApiModelProperty(value = "客户类型ID")
    @CounterField
    private String customerTypeId;

    @ApiModelProperty(value = "客户类型描述")
    private String customerTypeName;

    @ApiModelProperty(value = "注册地址")
    private String registeredAddress;

    @ApiModelProperty(value = "新证号（三证合一）")
    private String newBusinessCertNumber;

    @ApiModelProperty(value = "法人代表")
    private String legalRepresentative;

    @ApiModelProperty(value = "是否为一般纳税人")
    private Integer isTaxpayers;

    @ApiModelProperty(value = "营业范围")
    private String businessScope;

    @ApiModelProperty(value = "银行账号")
    private String bankAccount;

    @ApiModelProperty(value = "开户银行")
    private String bank;

    @ApiModelProperty("客户电话")
    @CounterField
    private String mobile;

    @ApiModelProperty("最新认购时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date orderDate;

    @ApiModelProperty("最新认筹时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date raiseDate;

    @ApiModelProperty("最新签约时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date signDate;

    @ApiModelProperty("最新跟进时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date followLastDate;

    @ApiModelProperty("属性完成百分比")
    private Double completePercent;

    @ApiModelProperty("最近一次操作时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date lastActionDate;

    @ApiModelProperty("最近一次操作动作")
    private String lastAction;

    @ApiModelProperty("渠道信息")
    private String channelInfo;

    @ApiModelProperty("标签列表")
    private List<String> tags = new ArrayList<>();

    @ApiModelProperty("客户印象标签")
    private List<String> impressionTags;

    @ApiModelProperty(value = "意向等级，A-意向明确，可逼定成交;B-有意向，需引导意向项目;C-需长期跟进;D-无购房意向")
    private String grade;

    @ApiModelProperty(value = "手机号码1")
    @CounterField
    private String mobile1;
    @ApiModelProperty(value = "手机号码2")
    @CounterField
    private String mobile2;
    @ApiModelProperty(value = "其它地址sort1")
    @CounterField
    private String address1;

    @ApiModelProperty(value = "是否完成必填项（0-未完成，1-已完成）")
    private Integer isFilledInfo;

    @ApiModelProperty(value = "状态信息")
    private String stageInfo;

    public Integer getGender() {
        return gender == 2 ? null : gender;
    }

    public String getGrade() {
        return customerLabelName;
    }

    public Double getCompletePercent() {
        if (completePercent == null) {
            completePercent = NumberUtil.parseDouble(CommonUtil.countField(this));
        }
        return completePercent;
    }

    public List<String> getImpressionTags() {
        if (impressionTags == null) {
            impressionTags = CommonUtil.extractTags(this);
        }
        return impressionTags;
    }

    public List<String> getTags() {
        if (tags.size() > 0) {
            return tags;
        }
        if (StrUtil.isNotBlank(shareUserKey)) {
            String shareTag = "共享";
            if (StrUtil.isNotBlank(shareSaleMainName)) {
                //被共享人看，则显示对方姓名
                if (shareUserKey.equalsIgnoreCase(loginUserKey)) {
                    shareTag += "-" + saleMainName;
                } else {
                    shareTag += "-" + shareSaleMainName;
                }
            }
            tags.add(shareTag);
        }

        return tags;
    }

}
